<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

use think\Lang;

if (!function_exists('ajax')) {
    /**
     * API输出格式
     * @Author   Wcj
     * @email 1054487195@qq.com
     * @DateTime 2019/7/25 16:47
     * @param int $code
     * @param string $msg
     * @param null $data
     * @return \think\response\Json
     */
    function ajax($code = SUCCESS, $msg = null, $data = null)
    {
        return json(['code' => $code, 'msg' => $msg ?? Lang::get($code), 'data' => $data]);
    }
}

if (!function_exists('check_args')) {
    /**
     * 参数非空批量检测
     * @Author   Wcj
     * @email 1054487195@qq.com
     * @DateTime 2019/7/19 14:12
     * @param $params
     * @return array
     */
    function check_args($params)
    {
        if (!is_array($params) || empty($params)) return ['code' => ERROR, 'msg' => '参数错误'];
        foreach ($params as $k => $v) {
            if (empty($v)) return ['code' => ERROR, 'msg' => "缺少参数 ${k}"];
        }
        return ['code' => SUCCESS];
    }
}

if (!function_exists('dd')) {
    /**
     * 打印输出数据
     * @Author   Wcj
     * @DateTime 2018/11/29 13:40
     * @param $var
     */
    function dd($var)
    {
        if (is_bool($var)) {
            var_dump($var);
        } else if (is_null($var)) {
            var_dump(NULL);
        } else {
            echo "<pre style='padding:10px;border-radius:5px;background:#F5F5F5;border:1px solid #aaa;font-size:14px;line-height:18px;'>" . print_r($var, true) . "</pre>";
        }

        exit;
    }
}